package com.zm.demo.core.leetcode;

import java.util.List;

/**
 * 移除链表元素
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class RemoveElements {
    public ListNode removeElements(ListNode head, int val) {

        while (head != null && head.val == val){
          head = head.next;
        }

        if (head == null){
            return head;
        }



        ListNode calc = head;
        ListNode next = head.next;
        while (next != null){
            if (next.val != val){
                calc.next = next;
                calc = calc.next;
            }else {
                calc.next = null;
            }
            next = next.next;

        }
        return calc;

    }
}